﻿Public Class ToolTempV

    Private lblInput As TenKeyLabel

    Private fIsOnLabel As Boolean = False

    Public ReadOnly Property Tempreture1 As Single
        Get
            If IsNumeric(ltlTemp1.Text) Then
                Return CSng(ltlTemp1.Text)
            Else
                Return 0
            End If
        End Get
    End Property

    Public ReadOnly Property Tempreture2 As Single
        Get
            If IsNumeric(ltlTemp2.Text) Then
                Return CSng(ltlTemp2.Text)
            Else
                Return 0
            End If
        End Get
    End Property

    Public Property InputLabel As TenKeyLabel
        Get
            Return lblInput
        End Get
        Set(ByVal value As TenKeyLabel)

        End Set
    End Property

    Private Sub ToolTempH_FontChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.FontChanged
        ltlTemp1.Font = Me.Font
        ltlTemp2.Font = Me.Font

        Me.ltlTemp1.Height = Me.Font.Size * 2.5
        Me.ltlTemp1.Width = Me.Font.Size * 7.5

        Me.ltlTemp2.Height = Me.Font.Size * 2.5
        Me.ltlTemp2.Width = Me.Font.Size * 7.5

        ToolTempH_SizeChanged(sender, e)
    End Sub

    Private Sub ToolTempH_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged

        Me.ltlTemp1.Top = (Me.Height / 2 - ltlTemp1.Height) / 2
        Me.ltlTemp1.Left = (Me.Width - ltlTemp1.Width) / 2

        Me.ltlTemp2.Top = (Me.Height * 3 / 2 - ltlTemp2.Height) / 2
        Me.ltlTemp2.Left = (Me.Width - ltlTemp1.Width) / 2

        If Me.Width <= ltlTemp1.Width Then
            ltlTemp1.Left = -1
            ltlTemp2.Left = -1
            Me.Width = ltlTemp1.Width
        End If

        If Me.Height < ltlTemp1.Height + ltlTemp2.Height Then
            ltlTemp1.Top = -1
            ltlTemp2.Top = ltlTemp1.Bottom - 1
            Me.Height = ltlTemp1.Height + ltlTemp2.Height - 1
        End If

    End Sub

    Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
        If Not fIsOnLabel Then
            Exit Sub
        End If
        MyBase.OnClick(e)
    End Sub

    Private Sub ltlTemp1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ltlTemp1.Click
        lblInput = ltlTemp1.InputLabel
        fIsOnLabel = True
        Me.OnClick(e)
    End Sub

    Private Sub ltlTemp2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ltlTemp2.Click
        lblInput = ltlTemp2.InputLabel
        fIsOnLabel = True
        Me.OnClick(e)
    End Sub

    Private Sub ltlTemp1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ltlTemp1.MouseLeave
        fIsOnLabel = False
    End Sub

    Private Sub ltlTemp2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ltlTemp2.MouseLeave
        fIsOnLabel = False
    End Sub
End Class
